#include "addinfosup.h"
#include "ui_addinfosup.h"
#include <QPushButton>
#include <QRadioButton>
#include <QDebug>

addInfoSup::addInfoSup(QWidget *parent) :
  QWidget(parent),
  ui(new Ui::addInfoSup)
{
  ui->setupUi(this);

  Person = new Individual;
  IO = new IOinfo;

  connect(ui->radioButtonOwn, &QRadioButton::clicked, [=](){
    Person->ID = kOwner;
  });
  connect(ui->radioButtonStaff, &QRadioButton::clicked, [=](){
    Person->ID = kStaff;
  });

  connect(ui->radioButtonMan, &QRadioButton::clicked, [=](){
    Person->gender = kMale;
  });

  connect(ui->radioButtonWoman, &QRadioButton::clicked, [=](){
    Person->gender = KFemale;
  });

  connect(ui->radioButtonManIO, &QRadioButton::clicked, [=](){
    Person->gender = kMale;
  });

  connect(ui->radioButtonWomIO, &QRadioButton::clicked, [=](){
    Person->gender = KFemale;
  });



  connect(ui->ButtonCancle, &QPushButton::clicked, this, &QWidget::close);

  connect(ui->ButtonSave, &QPushButton::clicked, [=](){

    if (ui->stackedWidget->currentIndex()==0) { //添加工作人员或业主
      Person->name = ui->lineEditName->text();
      Person->age = ui->spinBoxAge->value();
      Person->buidid = ui->lineEditBuid->text();
      Person->address = ui->lineEditAddress->text();
      Person->connection = ui->lineEditTel->text();
      Person->temperature = ui->SpinBoxTemp->value();
      switch (ui->comboBox->currentIndex()) {
        case 0:
          Person->state = kHealth;
          break;
        case 1:
          Person->state = kSuspected;
          break;
        case 2:
          Person->state = kDiagnosed;
          break;
        default:
          break;
      }
      ui->lineEditName->clear();
      ui->lineEditBuid->clear();
      ui->lineEditTel->clear();
      ui->lineEditAddress->clear();
      ui->comboBox->setCurrentIndex(0);
      ui->spinBoxAge->clear();
    } else {  //添加出入信息
      IO->people.name = ui->lineEditNameIO->text();
      IO->people.temperature = ui->SpinBoxTempIO->value();
      IO->people.connection = ui->lineEditTelIO->text();
      IO->buildid = ui->lineEditBuidIO->text();
      IO->date = ui->dateEdit->text();
      IO->intime = ui->timeIn->text();
      IO->outtime = ui->timeEditOut->text();
      ui->lineEditTelIO->clear();
      ui->lineEditNameIO->clear();
      ui->lineEditBuidIO->clear();
      ui->timeIn->clear();
      ui->timeEditOut->clear();
      ui->dateEdit->clear();
    }

    emit Save();
    this->close();

  });


}

void addInfoSup::show_window() {
  if (tabpage_==2)  //添加出入信息
    ui->stackedWidget->setCurrentIndex(1);
  else  //添加业主或工作人员
    ui->stackedWidget->setCurrentIndex(0);
  this->show();
}

addInfoSup::~addInfoSup()
{
  delete ui;
}
